Skip to content

fix(audio): 空闲时释放提示音输出与防休眠占用 - #1248

Merged
appergb merged 1 commit into
Open-Less:betafrom
Rpeng666:fix/audio-cue-idle-release
Nov 26, 2026
Merged

appergb merged 1 commit into
Open-Less:betafrom
Rpeng666:fix/audio-cue-idle-release

Conversation

@Rpeng666

Copy link
Copy Markdown
Contributor

摘要

修复桌面 Web Audio 提示音在空闲时持续占用系统输出设备的问题。启动预热不检查 audioCueOnRecord,即使用户关闭提示音,胶囊窗口挂载仍会创建并 resume 一个 AudioContext;播放结束或停止也只停止 oscillator,没有释放 context。

在 macOS 安装版 v2.0.1-tauri 上进行了对照:退出应用后输出流和 coreaudiod 的 PreventUserIdleSystemSleep assertion 消失;重新启动但不听写便出现 BuiltInSpeakerDevice 输出及 assertion;关闭录音提示音后重新启动仍复现。听写结束时麦克风自身的 assertion 正常释放,但 WebKit 输出的 assertion 继续存在。当前 beta 仍保留相同预热和不释放路径。

修复 / 新增 / 改进

  • 移除胶囊窗口启动预热,只在真实录音边沿或设置预览时按需创建 AudioContext。
  • 最后一个音调结束时关闭 context;保留 315ms 音频时钟健康检查作为 onended 延迟、节点创建失败时的释放兜底,冻结时钟仍至多重建一次。
  • 停止正在播放的提示音时,在短释放尾音后关闭输出。保留原有快速录音的延迟提示音反馈和 400ms 截止时间。
  • 新增 disposeAudioCue():初次读取到禁用设置、实时关闭提示音、监听器卸载或原生所有权变化时,取消待恢复请求和计时器并关闭 context。迟到的 Promise / 旧 onended / 旧停止计时器不能干扰下一次播放。
  • 扩展实际运行时回归,覆盖自然结束、停止、快速连续触发、禁用/卸载、挂起/拒绝/冻结恢复、过期恢复、节点创建失败及无 onended 的兜底释放;新增监听器接入契约检查。

兼容

  • 不包含:ASR、录音输入、权限、音量、用户配置格式或原生音频引擎修改;不修改用户安装的应用。
  • 保留 Android 禁用及低内存原生 cue owner 的 Web Audio 隔离,设置页预览复用同一生命周期。
  • 每轮提示音后主动释放 context,下次播放重新创建;原有挂起恢复/快速录音测试继续保留。

测试计划

  • 命令:cd openless-all/app && npm run build;结果:TypeScript 和 Vite 生产构建通过(仅有既有 bundle-size warning)。
  • 命令:node scripts/audio-cue-runtime.test.mjs;结果:生命周期与恢复回归通过。
  • 命令:node scripts/audio-cue-listener-contract.test.mjs;结果:按需启动、禁用设置清理和 owner 隔离契约通过。
  • 独立运行 src/**/*.test.ts 全部 62 项;结果:通过,含 src/lib/audioCue.test.ts。
  • Prettier 检查全部四个改动文件,以及 git diff --check;结果:通过。
  • npm test 全量:生产构建及此前执行的脚本通过,随后 scripts/check-hotkey-injection.mjs 调用 Cargo 被本机 rustc 1.95.0 阻断(上游 openless-core 要求 1.99)。没有跳过或修改此门禁,需要上游 CI 继续确认。
  • 修复后的原生 macOS 包实测:本 PR 未构建/替换安装版。请在启动但未听写、关闭提示音并重启、正常/快速听写结束、设置预览结束后,结合 pmset -g assertions 和 coreaudiod 日志确认没有遗留 WebKit 输出 assertion,且提示音正常。
  • 证据路径:新增/扩展的两个 scripts/audio-cue-*.test.mjs;安装版的对照结果如摘要所述。未提交用户设置、听写内容或私人日志。

Copilot AI balanced review requested due to automatic review settings October 21, 2026 13:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@H-Chris233 H-Chris233 added area:recording Recording area bug Something isn't working needs-review Needs review needs-tests Needs tests P2 Medium priority Linux Linux-specific macOS macOS-specific Windows Windows-specific labels Oct 23, 2026
@H-Chris233 H-Chris233 self-assigned this Oct 28, 2026
@H-Chris233

Copy link
Copy Markdown
Collaborator

合并前必须补的证据
在修复后的 macOS 安装包上执行:

  1. 启动但不听写,确认 pmset -g assertions 没有新增 WebKit 输出 assertion。
  2. 关闭录音提示音后重启,再检查一次。
  3. 正常听写结束、快速听写结束、设置页预览结束后分别检查输出设备是否释放。
  4. 结合 coreaudiod 日志确认没有遗留输出流。

@H-Chris233

Copy link
Copy Markdown
Collaborator

@appergb 来验收 审查没问题

@appergb appergb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请求修改,本 PR 不予通过。

  1. 当前 PR 涉及的 UI/交互方向与现版本不一致,现有 UI 问题不是局部音频提示音修复可以覆盖的范围。
  2. 新版本已经重构整套 UI 逻辑和页面衔接方式,本 PR 基于旧的 UI 逻辑继续修改,不能作为当前版本的合并基础。

请不要按当前 PR 继续合并。后续如果重新提交,需要基于当前版本的 UI 架构和交互逻辑重新整理,并先解决整套 UI 一致性问题。

@appergb

appergb commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

这个 PR 的更改暂时不予通过:它与当前 UI 设计方向不一致,并且在 macOS 端完全无法正常使用,与当前的 UI 和目标方向不一致,暂时搁置。

@appergb appergb added the branch-retained Keep source branch while the pull request remains open label Oct 30, 2026
@appergb
appergb merged commit 68c7ede into Open-Less:beta Nov 26, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recording Recording area branch-retained Keep source branch while the pull request remains open bug Something isn't working Linux Linux-specific macOS macOS-specific needs-review Needs review needs-tests Needs tests P2 Medium priority Windows Windows-specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants